package conversation

// 文件定义的逻辑已被弃用

import (
	"context"
	"im_sys/apps/im/immodels"
	"im_sys/apps/im/ws/internal/svc"
	"im_sys/apps/im/ws/ws_server"
	"im_sys/apps/im/ws/ws_struct"
	"im_sys/pkg/wuid"
	"time"
)

type Conversation struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	server *ws_server.Server
}

func NewConversation(ctx context.Context, svcCtx *svc.ServiceContext, server *ws_server.Server) *Conversation {
	return &Conversation{ctx: ctx, svcCtx: svcCtx, server: server}
}

// SingleChat 用户私聊业务
func (l *Conversation) SingleChat(data *ws_struct.Chat) error {
	if data.ConversationId == "" {
		data.ConversationId = wuid.CombineId(data.RecvId, data.SendId)
	}

	// 保存消息到mongodb数据库
	chatLog := immodels.ChatLog{
		ConversationId: data.ConversationId,
		SendId:         data.SendId,
		RecvId:         data.RecvId,
		MsgFrom:        0,
		ChatType:       data.ChatType,
		MsgType:        data.MType,
		MsgContent:     data.Content,
		SendTime:       time.Now().UnixNano(),
		Status:         0,
	}
	err := l.svcCtx.ChatLogModel.Insert(l.ctx, &chatLog)
	return err
}
